package com.restaurant.springboot.controller;

import com.restaurant.springboot.exception.TokenInvalidException;
import com.restaurant.springboot.utils.RespEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import static com.restaurant.springboot.utils.RespCode.ILLEGALTOKEN;

/**
 * @Author jack
 * @Date:2019/7/30 22:37
 */
@ControllerAdvice
public class ErrorHandlerController {
    /**
     * API统一异常处理
     **/
    @ExceptionHandler(value = TokenInvalidException.class)
    @ResponseBody
    public RespEntity jsonApiErrorHandler(HttpServletRequest request, Exception e) {
        return new RespEntity(
                ILLEGALTOKEN,
                e
        );
    }

}
